## config rules ##
project(tiny-objc-rt C)

cmake_minimum_required(VERSION 2.6)

set(VERSION_MAJOR "0")
set(VERSION_MINOR "2")
set(VERSION_PATCH "0")
set(TINY-OBJC-RT-VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(LIBNAME tiny-objc)

## compil rules ##

set(CMAKE_C_FLAGS "-std=c99 -W -Wall -Wextra -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign")
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

file(	GLOB_RECURSE
	source_tiny-objc-rt
	src/class.c
	src/dispatch.c
	src/init.c
	src/messaging.c
	src/object.m
	src/protocol.m
	src/string.m)

set_source_files_properties(${source_tiny-objc-rt} PROPERTIES LANGUAGE C)

add_library(${LIBNAME} ${source_tiny-objc-rt})
add_definitions(-D_BSD_SOURCE)

## add extra search paths for libraries and includes

SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
SET (LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE STRING "Directory where lib will install")
SET (INCLUDE_INSTALL_DIR "include" CACHE PATH "The directory the headers are installed in")
SET (CMAKE_MODULES_INSTALL_DIR "share/apps/cmake/modules" CACHE PATH "The directory to install FindQCommandLine.cmake to")

## Install rules ##

install(TARGETS ${LIBNAME} ARCHIVE
	DESTINATION lib/
	COMPONENT libraries)
install(FILES ${CMAKE_SOURCE_DIR}/include/class.h 
	DESTINATION include/tiny-objc/ 
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/dispatch.h 
	DESTINATION include/tiny-objc/
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/malloc.h
	DESTINATION include/tiny-objc/
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/objc.h
	DESTINATION include/tiny-objc/
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/rt.h
	DESTINATION include/tiny-objc/
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/fwk/object.h
	DESTINATION include/tiny-objc/fwk
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/fwk/protocol.h
	DESTINATION include/tiny-objc/fwk
	COMPONENT devel)
install(FILES ${CMAKE_SOURCE_DIR}/include/fwk/string.h
	DESTINATION include/tiny-objc/fwk
	COMPONENT devel)

## pkg-config ##

CONFIGURE_FILE(	${CMAKE_CURRENT_SOURCE_DIR}/tiny-objc.pc.in
		${CMAKE_CURRENT_SOURCE_DIR}/tiny-objc.pc
		@ONLY)
INSTALL(FILES	${CMAKE_CURRENT_SOURCE_DIR}/tiny-objc.pc
		DESTINATION lib${LIB_SUFFIX}/pkgconfig
		COMPONENT devel)

## Package rules ##

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "tiny-objc-rt")
set(CPACK_PACKAGE_VENDOR "pmbsd.org")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_PACKAGE_CONTACT "Sylvestre Gallon <ccna.syl@gmail.com>")
set(CPACK_PACKAGE_VENDOR "http://code.google.com/p/tiny-objc-rt")

set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_VERSION ${TINY-OBJC-RT-VERSION})
set(CPACK_PACKAGE_VERSION ${TINY-OBJC-RT-VERSION})

set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE")

set(CPACK_SOURCE_IGNORE_FILES
	"~$"
	"^${PROJECT_SOURCE_DIR}/\\\\.hg"
	"^${PROJECT_SOURCE_DIR}/build/"
	"^${PROJECT_SOURCE_DIR}/bin/")

set(CPACK_COMPONENTS_ALL libraries devel)
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Library")
set(CPACK_COMPONENT_DEVEL_DISPLAY_NAME "Developement files")
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "An objc runtime")
set(CPACK_COMPONENT_DEVEL_DESCRIPTION "developpement files for objc runtime")
set(CPACK_COMPONENT_DEVEL_DEPENDS libraries)

set(CPACK_PACKAGE_FILE_NAME "tiny-objc-rt-${CPACK_VERSION}-${CMAKE_SYSTEM_NAME}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "tiny-objc-rt-${CPACK_VERSION}")
set(CPACK_GENERATOR "DEB")
set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")

include(CPack)
